package com.cskaoyan.service;

import com.cskaoyan.mapper.AccountMapper;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;

/**
 * @author stone
 * @date 2022/06/18 11:40
 */
public class TransferTransactionCallBack implements TransactionCallback {

    AccountMapper accountMapper;
    Integer fromId;
    Integer destId;
    Integer fromMoney;
    Integer destMoney;

    public TransferTransactionCallBack(AccountMapper accountMapper, Integer fromId, Integer destId, Integer fromMoney, Integer destMoney) {
        this.accountMapper = accountMapper;
        this.fromId = fromId;
        this.destId = destId;
        this.fromMoney = fromMoney;
        this.destMoney = destMoney;
    }

    @Override
    public Object doInTransaction(TransactionStatus transactionStatus) {
        // 更新money
        int update1 = accountMapper.update(fromId, fromMoney);
        int i = 1 / 0;
        int update2 = accountMapper.update(destId, destMoney);
        return null;
    }
}
